package lc.q51_100;

import java.util.Arrays;
import java.util.Collections;
import java.util.stream.Collectors;

public class Q88 {

    public void merge(int[] nums1, int m, int[] nums2, int n) {
        int i = m - 1;
        int j = n - 1;
        int p = m + n -1;
        while (i >= 0 && j >= 0) {
            if (nums1[i] > nums2[j]) {
                nums1[p] = nums1[i];
                i --;
            } else {
                nums1[p] = nums2[j];
                j --;
            }
            p --;
        }
        while (j >= 0) {
            nums1[j] = nums2[j];
            j --;
        }
    }

    public static void main(String[] args) {
        int[] nums1 = {1,2,3,0,0,0};
        int[] num2 = {-1,5,6};
        Q88 q88 = new Q88();
        q88.merge(nums1, 3, num2, 3);
        System.out.println(Arrays.stream(nums1).mapToObj(String::valueOf)
                .collect(Collectors.joining(",")));
    }

}
